<template>
  <div class="item">
    <div class="content">
      <span class="index">{{ index + 1 }}.</span>{{ content }}
    </div>
    <div class="options">
      <div class="option" v-for="option in options" :key="option.id">
        <b>{{ option.id }}.</b>{{ option.text }}
      </div>
    </div>
    <div class="desc" v-if="displayDesc">
      <div><b>正确答案：</b>{{ answer }}</div>
      <div><b>解析：</b>{{ desc }}</div>
    </div>
    <div class="opts">
      <div class="labels">
        <span>选择题</span>
        <span>{{ knowledge }}</span>
      </div>
      <el-button
        :class="selected ? 'btn-active' : 'btn'"
        color="#43b883"
        :dark="selected"
        :plain="!selected"
        @click="$emit('add', id)"
        >{{ selected ? '移出试卷' : '加入试卷' }}</el-button
      >
    </div>
  </div>
</template>

<script setup>
defineProps([
  'index',
  'id',
  'content',
  'options',
  'answer',
  'desc',
  'displayDesc',
  'knowledge',
  'selected'
])
// 下标，id，题干，选项，答案，解析，是否显示解析，知识点，是否选择

defineEmits(['add'])
// 加入试卷
</script>

<style lang="scss" scoped>
.item {
  margin-bottom: 1rem;
  position: relative;
  line-height: 1.8;

  .content {
    .index {
      padding-right: 0.3rem;
    }
  }

  .options {
    margin-top: 0.4rem;
    display: flex;
    flex-wrap: wrap;
    margin-left: 1rem;

    .option {
      margin-right: 1rem;

      b {
        margin-right: 0.3rem;
      }
    }
  }

  .desc {
    margin-top: 0.4rem;
    b {
      font-weight: 700;
    }
  }

  .opts {
    display: flex;
    justify-content: space-between;
    margin-top: 1rem;

    .labels {
      display: flex;
      line-height: 1;

      span {
        color: #999;
        display: inline-block;
        height: 20px;
        padding: 0 0.5rem;
        border-right: 1px solid #ccc;
      }

      span:first-of-type {
        padding-left: 0;
      }

      span:last-of-type {
        border: 0;
      }
    }

    .btn {
      height: 30px;
    }

    .btn-active {
      height: 30px;
      color: #fff;
    }
  }
}
</style>
